package com.cy.device.action;

import com.cy.device.common.ResponseBean;
import com.cy.device.model.vo.DeviceConfigVO;
import com.cy.device.model.vo.DeviceControlVO;
import com.cy.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;

/**
 * @author: jiangwang
 * @created: 2023/10/26 9:42
 */
@Api(tags = "超远智能机柜")
@RestController
@RequestMapping(value = "/api/cy/cabinet")
public class DeviceAction {

    private final DeviceService deviceService;

    public DeviceAction(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    /**
     * 参数设置
     *
     * @param deviceConfigVO
     * @return
     */
    @PostMapping(value = "/setConfig")
    @ApiOperation(value = "参数配置", notes = "参数配置")
    public DeferredResult<ResponseBean> setConfig(@RequestBody DeviceConfigVO deviceConfigVO) {
        DeferredResult<ResponseBean> deferredResult = new DeferredResult<>(10000L);
        deviceService.setConfig(deviceConfigVO, deferredResult);
        return deferredResult;
    }

    /**
     * 参数读取
     *
     * @param deviceNo
     * @return
     */
    @GetMapping(value = "/queryConfig")
    @ApiOperation(value = "参数读取", notes = "参数读取")
    public DeferredResult<ResponseBean> queryConfig(String deviceNo) {
        DeferredResult<ResponseBean> deferredResult = new DeferredResult<>(10000L);
        deviceService.queryConfig(deviceNo, deferredResult);
        return deferredResult;
    }

    /**
     * 控制项读取
     *
     * @param deviceNo
     * @return
     */
    @GetMapping(value = "/queryControl")
    @ApiOperation(value = "控制项读取", notes = "控制项读取")
    public DeferredResult<ResponseBean> queryControl(String deviceNo) {
        DeferredResult<ResponseBean> deferredResult = new DeferredResult<>(10000L);
        deviceService.queryControl(deviceNo, deferredResult);
        return deferredResult;
    }

    /**
     * 控制项设置
     *
     * @param deviceControlVO
     * @return
     */
    @PostMapping(value = "/setControl")
    @ApiOperation(value = "控制项设置", notes = "控制项设置")
    public DeferredResult<ResponseBean> setControl(@RequestBody DeviceControlVO deviceControlVO) {
        DeferredResult<ResponseBean> deferredResult = new DeferredResult<>(10000L);
        deviceService.setControl(deviceControlVO, deferredResult);
        return deferredResult;
    }

    /**
     * 查询状态
     *
     * @param deviceNo
     * @return
     */
    @GetMapping(value = "/queryStatus")
    @ApiOperation(value = "设备状态查询", notes = "设备状态查询")
    public ResponseBean queryStatus(String deviceNo) {
        deviceService.queryStatus(deviceNo);
        return ResponseBean.success();
    }
}
